<template>
  <pageTabelLayout>
    <template #pageHeader>
      <div class="search-form isheader" v-if="headerShow">
        <div>
          <a-form size="small" :model="pageData" layout="inline" v-if="permissionStore.hasPermisson('cdmc.cx')">
            <a-form-item label="疵点名称">
              <!-- <a-select popup-container="html"  class="bacClass" :style="{ width: '200px' }" :loading="loading" @search="handleSearch"
                                v-model="pageData.dropDownData" :filter-option="false" allow-search allow-clear
                                @focus="focusSel">
                                <a-option v-for="item in pageData.DefectNameList" :value="item['defectName']">{{
                                        item["defectName"]
                                }}
                                </a-option>
                            </a-select> -->
              <a-input :style="{ width: '200px' }" allow-clear class="bacClass" placeholder=""
                v-model="pageData.dropDownData" @press-enter="huiche" />
            </a-form-item>
          </a-form>
        </div>
        <div>
          <Toolbar :items="pageData.btnList" @add="addHandler" @import="importHandler" @del="deleteHandler"
            @select="selectHandler" @export="exports" @excel="downloadHandler">
          </Toolbar>
        </div>
      </div>
      <div class="my-divisders">
        <a-divider orientation="center">
          <icon-double-up v-if="headerShow" @click="headerShow = false" :strokeWidth="2" :size="18" />
          <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18" />
        </a-divider>
      </div>
      <div class="my-tool-bar">
        <!-- <Toolbar :items="pageData.btnList" @add="addHandler" @import="importHandler" @del="deleteHandler"
                        @select="selectHandler" @export="exports" @excel="downloadHandler">
                    </Toolbar> -->
      </div>
    </template>

    <template #pageTabel>
        <!-- <a-tab-pane> -->
        <!-- <a-table style="height:100%" :scrollbar="true" sticky-header @page-change="pagination.change" stripe
                            :bordered="true" :columns="tableColumns" size="mini" @change="handleChange"
                            :draggable="{ type: 'handle', width: 20, fixed: true }"
                            :row-selection="{ showCheckedAll: true, width: 50, onlyCurrent: true }"
                            v-model:selected-keys="selectedRowKeys" :loading="pageData.pageLoading" :data="table.dataList"
                            :pagination="false" :rowKey="rowKey">
                            <template #action="{ record }">
                                <a-button type="primary" size="small" status="warning" @click="editHandler(record)"
                                    :disabled="!pageData.isEdit">
                                    <template #icon>
                                        <icon-edit />
                                    </template>
                                    修 改
                                </a-button>
                            </template>
                            <template #leJuan="{ record }">
                                <div>{{ record.deleteDonation === 0 ? "是" : "否" }}</div>
                            </template>

                        </a-table> -->
        <a-spin :loading="pageData.pageLoading" tip="加载中" dot style="height: 100%; width: 100%; z-index: 999">
          <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true" :suppressDragLeaveHidesColumns="true" rowSelection="multiple"
            @grid-ready="gridReady" style="height: calc(100% - 40px);" :defaultColDef="defaultColDef" class="ag-theme-alpine"
            :rowData="table.dataList" :columnDefs="tc" :localeText="localeText1" @columnResized="onColumnResized"
            @columnMoved="onColumnMoved" @columnVisible="onColumnVisible"></AgGridVuesCopys>
            <paginationCopys :total="total" show-total show-jumper show-page-size @change="PageSize" @page-size-change="change1"
      style="justify-content: center" :page-size="pagination.pageSize" :current="pagination.page"
      :page-size-options="pagingList1" />
        </a-spin>
        <!-- </a-tab-pane> -->
      
    </template>
    

    <a-drawer style="z-index: 999" ok-text="保存" cancel-text="关闭" :drawer-style="{ zIndex: 9999 }" :mask-closable="false"
      :width="400" :visible="pageData.showAdd" unmountOnClose @ok="sideOk" @cancel="pageData.showAdd = false"
      :ok-loading="pageData.pageLoading">
      <template #title>
        {{ pageData.sideTitle }}
      </template>
      <div>
        <a-form ref="formRef" layout="horizontal" :model="dataForm">
          <a-form-item label-col-flex="80px" label="疵点类别" field="category" :validate-trigger="['change', 'blur']"
            :rules="[{ required: true, message: '疵点类别必填,如没有类别请在字典里添加!' }]">
            <a-select popup-container="html"  class="bacClass" v-model="dataForm.category" @focus="focusSel1">
              <a-option v-for="item in pageData.DefectNameList" :value="item['detailName']">{{ item['detailName'] }}
              </a-option>
            </a-select>
          </a-form-item>
          <a-form-item label-col-flex="80px" label="疵点编号" field="clothtypeCode"
            :rules="[{ validator: isChiese }, { required: true, message: '疵点编号必填' }]"
            :validate-trigger="['change', 'blur']">
            <a-input class="bacClass" v-model="dataForm.clothtypeCode" @blur="inputBlur" />
          </a-form-item>
          <a-form-item label-col-flex="80px" label="疵点名称" field="defectName" :validate-trigger="['change', 'blur']"
            :rules="[{ required: true, message: '疵点名称必填' }]">
            <a-input class="bacClass" v-model="dataForm.defectName" />
          </a-form-item>
          <a-form-item label-col-flex="80px" label="疵点等级" field="defectGrade" :validate-trigger="['change', 'blur']"
            :rules="[{ required: true, message: '疵点等级必填' }]">
            <a-input class="bacClass" v-model="dataForm.defectGrade" />
          </a-form-item>
          <a-form-item label-col-flex="80px" label="疵点分值" field="defectGrade" :validate-trigger="['change', 'blur']"
            :rules="[{ required: true, message: '疵点分值必填' }]">
            <a-input-number class="bacClass input-demo" v-model="dataForm.scorex" :min="0" :max="10000000000"
              :precision="2" />
          </a-form-item>
          <a-form-item label-col-flex="80px" label="是否乐捐" field="deleteDonation">
            <a-select popup-container="html"  class="bacClass" v-model="dataForm.deleteDonation" @change="changeLj">
              <a-option :value="0">是</a-option>
              <a-option :value="1">否</a-option>
            </a-select>
          </a-form-item>
          <a-form-item label-col-flex="80px" label="乐捐金额" field="donationMoney" :disabled="pageData.isDisable">
            <a-input-number v-model="dataForm.donationMoney" class="input-demo" :min="0"
              :class="{ bacClass: !pageData.isDisable }" :max="10000000000" :precision="2" />
          </a-form-item>
          <a-form-item label-col-flex="80px" label="备注" field="remark">
            <a-textarea class="bacClass" placeholder="" v-model="dataForm.remark" :max-length="400" allow-clear
              show-word-limit />
          </a-form-item>
        </a-form>
      </div>
    </a-drawer>
  </pageTabelLayout>
</template>

<script lang="ts">
import { post } from '@/api/http'
import { useTable, useRowKey, useTableColumn, usePagination, useRowSelection } from '@/hooks/table'

import { ref, reactive, onMounted, onActivated, onUnmounted } from 'vue'
import Toolbar from '@/components/Toolbar.vue'
import { Form, Message, Modal } from '@arco-design/web-vue'
import { FormInstance } from '@arco-design/web-vue/es/form'
import emitter from '@/hooks/useEventBus'
import validate from '@/hooks/useValidate'
import { DatasetComponent } from 'echarts/components'
import { baseURL } from '../../../api/axios.config'
import axios from 'axios'
import usePermission from '@/store/modules/permission'

import filedownload from 'js-file-download'
import { localeText } from '@/api/aggridZw'
import { pagingList } from '@/api/paging'
import { saveOrUpdateGridState as saveOrUpdateGridState01 } from '@/hooks/useGridState'
interface DefectName {
  id: any
  clothtypeCode: any
  defectName: string | undefined
  defectGrade: string | undefined
  deleteDonation: number | undefined
  donationMoney: number | undefined
  deleteState: number | undefined
  createName: string | undefined
  createTime: string | undefined
  updateName: string | undefined
  updateTime: string | undefined
  serialNumber: number | undefined
  category: string | undefined
  remark: string | undefined
  scorex: any
}

export default {
  name: 'DefectName',
  setup() {
    //查询
    const scrollbar = ref(true)
    const total = ref(10)
    const page = ref(1)
    const size = ref(10)
    function PageSize(val: any) {
      pagination.page = val
      doRefresh()
    }

    function change1(val: any) {
      pagination.pageSize = val
      doRefresh()
    }

    function doRefresh() {
      pageData.pageLoading = true
      updateGridState01()
      post({
        url: 'qms/defectType/selectPage',
        data: {
          page: pagination.page,
          size: pagination.pageSize,
          deleteState: 0,
          defectName: pageData.dropDownData,
        },
      })
        .then(({ data, code }: any) => {
          if (code === 200) {
            table.handleSuccess(data.list)
            gridOption.value.setRowData(data.list)
            //pagination.setTotalSize(data.total);
            total.value = data.total
          }
        })
        .catch(console.log)
        .finally(() => {
          pageData.pageLoading = false
        })
    }

    const { selectedRowKeys, onSelectionChange } = useRowSelection()
    const pagination = usePagination(doRefresh)
    const table = useTable()
    const rowKey = useRowKey('id')
    //检验表单是否含有中文的方法
    const hasChiese = validate.includeChinese
    const tableColumns = useTableColumn([
      {
        title: '序号',
        key: 'serialNumber',
        dataIndex: 'serialNumber',
        width: 150,
      },
      {
        title: '类别',
        key: 'category',
        dataIndex: 'category',
        width: 150,
      },
      {
        title: '疵点编号',
        key: 'clothtypeCode',
        dataIndex: 'clothtypeCode',
        width: 150,
      },
      {
        title: '疵点名称',
        key: 'defectName',
        dataIndex: 'defectName',
        width: 150,
      },
      {
        title: '疵点等级',
        key: 'defectGrade',
        dataIndex: 'defectGrade',
        width: 150,
      },
      {
        title: '疵点分值',
        key: 'scorex',
        dataIndex: 'scorex',
        width: 150,
      },

      {
        title: '乐捐金额',
        key: 'donationMoney',
        dataIndex: 'donationMoney',
        width: 150,
      },
      {
        title: '备注',
        key: 'remark',
        dataIndex: 'remark',
        width: 150,
      },
      {
        title: '创建人',
        key: 'createName',
        dataIndex: 'createName',
        width: 150,
      },
      {
        title: '创建时间',
        key: 'createTime',
        dataIndex: 'createTime',
        width: 200,
      },
      {
        title: '最后修改人',
        key: 'updateName',
        dataIndex: 'updateName',
        width: 150,
      },
      {
        title: '最后修改时间',
        key: 'updateTime',
        dataIndex: 'updateTime',
        width: 200,
      },
      {
        title: '是否乐捐',
        key: 'deleteDonation',
        dataIndex: 'deleteDonation',
        width: 150,
        slotName: 'leJuan',
        fixed: 'right',
      },
      {
        title: '操作',
        key: 'id',
        dataIndex: 'id',
        slotName: 'action',
        width: 150,
        fixed: 'right',
      },
    ])
    const scroll = {
      x: 2000,
      y: 200,
    }
    let tc: any[] = tableColumns.map((o) => {
      let obj = {
        headerName: o.title,
        field: o.key,
        pinned: o['fixed'],
        tooltipField: o.key,
      }

      if (o.slotName === 'action') {
        obj['resizable'] = false
        obj['filter'] = false
        obj['sortable'] = false
        obj['lockPosition'] = 'right'
        obj['width'] = 80
        obj['cellRenderer'] = {
          template: `<el-button style="color:#165dff;"  v-if="isEdit" link  @click="a">修改</el-button>`,
          setup(props: any) {
            let isEdit = permissionStore.hasPermisson('cdmc.xg')
            const a = () => {
              editHandler(props.params.data)
            }
            return {
              isEdit,
              a,
            }
          },
        }
      }
      if (o.slotName === 'leJuan') {
        obj['resizable'] = false  
        obj['sortable'] = false
        obj['width'] = 150
        obj['cellRenderer'] = {
          template: `<el-tag type="warning" v-if="params.data.deleteDonation==1">{{val}}</el-tag><el-tag type="success" v-else>{{val}}</el-tag>`,
          setup(props: any) {
            let val = ref()
            console.log(props.params.data.deleteDonation)

            if (props.params.data.deleteDonation == 0) {
              val.value = '是'
            } else {
              val.value = '否'
            }

            return {
              val,
            }
          },
        }
        obj['filterParams'] = {
      valueFormatter: function (params: any) {
        return params.value == '0'
          ? '是'
          : params.value == '1'
          ? '否'
          : ''
      },
    }
      }

      return obj
    })

    let a = [
      {
        showRowGroup: 'hide_def',
        headerName: '',
        checkboxSelection: true,
        headerCheckboxSelection: true,
        pinned: 'left',
        width: 50,
        resizable: false,
        filter: false,
        sortable: false,
        minWidth: 50,
        maxWidth: 50,
        lockPosition: 'left',
      },
    ]
    tc = a.concat(tc)
    const tablediv = ref(null)
    const pageData = reactive<{
      DefectName: DefectName[]
      showAdd: boolean
      sideTitle: string
      dropDownData: any
      pageLoading: boolean
      height: number
      tablediv: any
      rHeight: number | undefined
      DefectNameList: []
      isDisable: boolean
      btnList: any[]
    }>({
      DefectName: [],
      showAdd: false,
      sideTitle: '新增疵点名称',
      dropDownData: '',
      pageLoading: false,
      height: 0,
      tablediv: null,
      rHeight: 0,
      DefectNameList: [],
      isDisable: false,
      btnList: [],
    })
    //下拉框得到焦点
    const focusSel = () => {
      selCxAll({ defectName: '' })
    }
    //下拉数据
    const options = ref<any>(pageData.DefectNameList)
    const loading = ref(false)
    const handleSearch = (value: any) => {
      if (value) {
        const ob = { defectName: value }
        loading.value = true
        window.setTimeout(() => {
          selCxAll(ob)
          options.value = pageData.DefectNameList
          loading.value = false
        }, 200)
      } else {
        options.value = []
      }
    }

    //下拉框查询
    function selCxAll(val: any) {
      post({
        url: 'qms/defectType/getFieldValue',
        data: val,
      }).then(({ data, code }: any) => {
        if (code === 200) {
          console.log(data)
          // (data as string[]).splice(0, 0, "全部");
          pageData.DefectNameList = data
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    }

    //类别下拉款
    const focusSel1 = () => {
      post({
        url: 'dict/dictTypeDetail/getListByCodeType?codeType=15',
      }).then(({ data, code }: any) => {
        if (code === 200) {
          pageData.DefectNameList = data
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    }

    onMounted(() => {
      emitter.on('refresh-DefectName', () => {
        // doRefresh();
        selCxAll({ defectName: '' })
      })
      pageData.rHeight = document.getElementById('masterDataSettings')?.clientHeight
      //表格的高
      if (pageData.rHeight !== undefined) {
        pageData.rHeight = pageData.rHeight - 200
      }

      window.addEventListener('resize', () => {
        pageData.rHeight = document.getElementById('masterDataSettings')?.clientHeight

        //表格的高
        if (pageData.rHeight !== undefined) {
          pageData.rHeight = pageData.rHeight - 200
        }
      })
      doRefresh()
    })

    //查询
    const selectHandler = () => {
      pagination.page = 1
      doRefresh()
    }
    const queryData = reactive({
      clothType: '',
    })
    const addHandler = () => {
      for (var key in dataForm) {
        if (key === 'id') {
          dataForm[key] = null
        } else if (
          key === 'deleteState' ||
          key === 'donationMoney' ||
          key === 'deleteDonation' ||
          key === 'scorex'
        ) {
          dataForm[key] = 0
        } else {
          dataForm[key] = ''
        }
      }
      pageData.showAdd = true
      pageData.sideTitle = '新增疵点名称'
    }
    const dataForm = reactive<DefectName>({
      id: null,
      clothtypeCode: '',
      defectName: '',
      defectGrade: '',
      deleteDonation: 0,
      donationMoney: 0,
      deleteState: 0,
      createName: '',
      createTime: '',
      updateName: '',
      updateTime: '',
      category: '',
      serialNumber: 0,
      remark: '',
      scorex: 0,
    })

    // 表格准备事件
    const gridOption = ref()
    const colState = ref()
    const gridReady = (params: any) => {
      gridOption.value = params.api
      colState.value = params.columnApi
    }

    const formRef = ref<FormInstance>()
    const sideOk = () => {
      formRef.value?.validate().then((err) => {
        if (!err) {
          if (pageData.sideTitle === '新增疵点名称') {
            pageData.pageLoading = true
            post({
              url: 'qms/defectType/insert',
              data: [dataForm],
            })
              .then((res: any) => {
                if (res.code === 200) {
                  formRef.value?.resetFields()

                  pageData.showAdd = false

                  Message.success({
                    content: '新增成功',
                    duration: 5000,
                  })
                  doRefresh()
                } else {
                  Message.error({
                    content: res.message,
                    duration: 5000,
                  })
                }
                doRefresh()
              })
              .finally(() => {
                doRefresh()
                pageData.pageLoading = false
              })
          } else {
            pageData.pageLoading = true
            post({
              url: 'qms/defectType/update',
              data: [dataForm],
            })
              .then((res: any) => {
                if (res.code === 200) {
                  formRef.value?.resetFields()
                  pageData.showAdd = false

                  Message.success({
                    content: '修改成功',
                    duration: 5000,
                  })
                  doRefresh()
                } else {
                  Message.error({
                    content: res.message,
                    duration: 5000,
                  })
                }
              })
              .finally(() => {
                doRefresh()
                pageData.pageLoading = false
              })
          }
        }
      })
    }
    const deleteHandler = () => {
      if (gridOption.value.getSelectedRows() === 0) {
        return
      }
      Modal.confirm({
        title: '系统提示',
        content: '确认删除选中的数据?',
        onOk() {
          pageData.pageLoading = true
          post({
            url: 'qms/defectType/delete',
            data: gridOption.value.getSelectedRows().map((o: any) => {
              return o.id
            }),
          })
            .then(({ code, data, message }: any) => {
              if (code === 200) {
                Message.success({
                  content: '删除成功',
                  duration: 5000,
                })
                pagination.page = 1
                doRefresh()
              } else {
                Message.error({
                  content: message,
                  duration: 5000,
                })
              }
            })
            .finally(() => {
              pageData.pageLoading = false
            })
        },
      })
    }
    const editHandler = (record: DefectName) => {
      dataForm.id = record.id
      dataForm.clothtypeCode = record.clothtypeCode
      dataForm.defectName = record.defectName
      dataForm.deleteDonation = record.deleteDonation
      dataForm.defectGrade = record.defectGrade
      dataForm.donationMoney = record.donationMoney
      dataForm.serialNumber = record.serialNumber
      dataForm.category = record.category
      dataForm.remark = record.remark
      pageData.sideTitle = '修改疵点名称'
      pageData.showAdd = true
      if (record.deleteDonation === 0) {
        pageData.isDisable = false
      } else {
        pageData.isDisable = true
        dataForm.donationMoney = 0
      }
    }
    //判断是否填写了中文
    const isChiese = (value: string, cb: Function) => {
      return new Promise<void>((resolve) => {
        if (window.encodeURI(value).indexOf('%') !== -1) {
          cb('填写的值只能是英文数字组合或英文，数字！')
        }
        resolve()
      })
    }
    //input离开焦点 将小写转大写
    const inputBlur = () => {
      dataForm.clothtypeCode = dataForm.clothtypeCode.toUpperCase()
    }
    //导出
    const exports = () => {
      // if (selectedRowKeys.value.length === 0) {
      //     Message.error('请先勾选')
      //     return
      // }
      if (gridOption.value.getSelectedRows() === 0) {
        Message.error('请先勾选')
        return
      } else {
        //将表头拼接出来
        let head =
          '<th>序号</th><th>类别</th><th>疵点编号</th><th>疵点名称</th><th>疵点等级</th><th>疵点分值</th><th>是否乐捐</th><th>乐捐金额</th><th>备注</th><th>创建人</th><th>创建时间</th><th>最后修改人</th><th>最后修改时间</th>'
        //拿到当前表格数据与勾选的行做筛选

        // let nowRow = table.dataList.filter(function (o) {
        //     return selectedRowKeys.value.indexOf(o["id"]) !== -1;
        // })
        let nowRow = gridOption.value.getSelectedRows()
        let body = ''
        nowRow.forEach(function (o: any) {
          body += '<tr>'
          // body += "<td>" + (o["hACacidity"] == undefined ? "" : o["hACacidity"]) + "</td>";
          body += '<td>' + (o['serialNumber'] == undefined ? '' : o['serialNumber']) + '</td>'
          body += '<td>' + (o['category'] == undefined ? '' : o['category']) + '</td>'
          body += '<td>' + (o['clothtypeCode'] == undefined ? '' : o['clothtypeCode']) + '</td>'
          body += '<td>' + (o['defectName'] == undefined ? '' : o['defectName']) + '</td>'
          body += '<td>' + (o['defectGrade'] == undefined ? '' : o['defectGrade']) + '</td>'
          body += '<td>' + (o['scorex'] == undefined ? '' : o['scorex']) + '</td>'
          body += '<td>' + (o['deleteDonation'] == 0 ? '是' : '否') + '</td>'
          body += '<td>' + (o['donationMoney'] == undefined ? '' : o['donationMoney']) + '</td>'
          body += '<td>' + (o['remark'] == undefined ? '' : o['remark']) + '</td>'
          body += '<td>' + (o['createName'] == undefined ? '' : o['createName']) + '</td>'
          body += '<td>' + (o['createTime'] == undefined ? '' : o['createTime']) + '</td>'
          body += '<td>' + (o['updateName'] == undefined ? '' : o['updateName']) + '</td>'
          body += '<td>' + (o['updateTime'] == undefined ? '' : o['updateTime']) + '</td>'
          body += '</tr>'
        })
        tableToXlsx(head, '疵点名称', body)
        console.log(table)
      }
    }

    function tableToXlsx(head: any, filename: any, body: any) {
      const uri = 'data:application/vnd.ms-excel;base64,',
        template = `<html>
            <head><meta charset="UTF-8"></head>
            <body><table border="1"><tr>${head}</tr>${body}</table></body>
        </html>`

      const a = document.createElement('a')
      a.href = uri + window.btoa(unescape(encodeURIComponent(template)))
      a.download = filename
      a.click()
      document.removeChild(a)
    }

    //模板下载
    const downloadHandler = () => {
      axios
        .get(baseURL + '/qms/defectType/uploadModel', {
          responseType: 'blob',
          headers: {
            token: sessionStorage.getItem('USER-TOKEN-KEY'),
          },
        })
        .then((res) => {
          if (res.status === 200) {
            filedownload(res.data, '疵点名称.xlsx')
          }
        })
      // window.open(baseURL + '/product/mercery/uploadMerceryModel')
    }
    //导入
    const importHandler = () => {
      const inputEle: HTMLInputElement = document.createElement('input')
      inputEle.type = 'file'
      inputEle.id = 'fileUploadExcel'
      inputEle.accept =
        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel'
      inputEle.addEventListener('change', (e) => {
        const formData = new FormData()
        if (inputEle.files !== null) {
          formData.append('file', inputEle.files[0] || '')
        } else {
          Message.warning('未选择文件！')
          return
        }
        pageData.pageLoading = true
        axios
          .post(baseURL + '/qms/defectType/importModelData', formData, {
            headers: {
              'Content-Type': 'multipart/form-data',
              token: sessionStorage.getItem('USER-TOKEN-KEY'),
            },
          })
          .then((result) => {
            if (result.data['code'] === 200) {
              Message.success('导入成功')
            } else {
              Message.error(result.data.message)
            }
          })
          .finally(() => {
            pageData.pageLoading = false
            doRefresh()
          })
      })
      inputEle.click()
    }
    //乐捐是 填写金额 否 不能填写
    const changeLj = (val: any) => {
      if (val === 0 || val === '是') {
        pageData.isDisable = false
      } else {
        pageData.isDisable = true
        dataForm.donationMoney = 0
      }
    }
    const headerShow = ref<boolean>(true)
    //设置权限
    // ['查询', '新增', '删除', '导出', '导入']
    const permissionStore = usePermission()

    if (permissionStore.hasPermisson('cdmc.cx')) {
      pageData.btnList.push('查询')
    }
    if (permissionStore.hasPermisson('cdmc.xz')) {
      pageData.btnList.push('新增')
    }
    if (permissionStore.hasPermisson('cdmc.sc')) {
      pageData.btnList.push('删除')
    }
    if (permissionStore.hasPermisson('cdmc.dc')) {
      pageData.btnList.push('导出')
    }
    if (permissionStore.hasPermisson('cdmc.dr')) {
      pageData.btnList.push('导入')
    }
    if (permissionStore.hasPermisson('cdmc.mbxz')) {
      pageData.btnList.push('模板下载')
    }
    const handleChange = (_data: any) => {
      table.handleSuccess(_data)
    }
    const defaultColDef = {
      sortable: true,
      resizable: true,
      filter: true,
      // flex: 1
    }
    const huiche = () => {
      doRefresh()
    }
    const localeText1: any = ref(localeText)
    const pagingList1: any = ref(pagingList)

    const { saveGridState: saveGridState01, updateGridState: updateGridState01 } = saveOrUpdateGridState01('DefectName', gridOption, colState, tc)
    const onColumnMoved = () => {
      saveGridState01()
    }
    const onColumnResized = () => {
      saveGridState01()
    }
    const onColumnVisible = () => {
      saveGridState01()
    }
    return {
      saveOrUpdateGridState01,
      saveGridState01,
      updateGridState01,
      onColumnMoved,
      onColumnResized,
      onColumnVisible,
      colState,
      pagingList1,
      huiche,
      localeText1,
      headerShow,
      scroll,
      scrollbar,
      tablediv,
      total,
      downloadHandler,
      importHandler,
      hasChiese,
      deleteHandler,
      sideOk,
      formRef,
      dataForm,
      addHandler,
      selectedRowKeys,
      pagination,
      tableColumns,
      table,
      rowKey,
      pageData,
      queryData,
      editHandler,
      selectHandler,
      options,
      loading,
      handleSearch,
      inputBlur,
      isChiese,
      exports,
      focusSel,
      changeLj,
      focusSel1,
      handleChange,
      PageSize,
      change1,
      defaultColDef,
      tc,
      gridOption,
      gridReady,
      permissionStore,
    }
  },
  components: { Toolbar,  },
}
</script>
<style scoped lang="less"></style>
